1925B - A Balanced Problemset - CodeForces Solution


greedy math number theory

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000010000
#define endl '\n'

//factors of x
vector<int> factorization(int x) {
    vector<int> fac;
    for (int i = 1; i * i <= x; i++) {
        if (x % i == 0) {
            fac.push_back(i);
            if (i != x / i) {
                fac.push_back(x / i);
            }
        }
    }
    return fac;
}


void solve(){
	int x,n;
	cin>>x>>n;
	vector<int>fac = factorization(x);

	sort(fac.begin(),fac.end());
	auto it = lower_bound(fac.begin(), fac.end(), n);
    
    if (it != fac.end()) {
        cout << (x / *it )<< endl;
    } else {
        cout << "1" << endl;  // Handle the case when no factor is found
    }
}
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int _t; cin>>_t;while(_t--)
	solve();
}


Comments

Submit
0 Comments
More Questions

107B - Basketball Team
245A - System Administrator
698A - Vacations
1216B - Shooting
368B - Sereja and Suffixes
1665C - Tree Infection
1665D - GCD Guess
29A - Spit Problem
1097B - Petr and a Combination Lock
92A - Chips
1665B - Array Cloning Technique
1665A - GCD vs LCM
118D - Caesar's Legions
1598A - Computer Game
1605A - AM Deviation
1461A - String Generation
1585B - Array Eversion
1661C - Water the Trees
1459A - Red-Blue Shuffle
1661B - Getting Zero
1661A - Array Balancing
1649B - Game of Ball Passing
572A - Arrays
1455A - Strange Functions
1566B - MIN-MEX Cut
678C - Joty and Chocolate
1352E - Special Elements
1520E - Arranging The Sheep
1157E - Minimum Array
1661D - Progressions Covering